/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BuscarCasos.java
 *
 * Created on 21/07/2011, 06:45:10 PM
 */
package bufete;

import callProcs.ProcsInsertar;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Jito
 */
public class BuscarCasos extends javax.swing.JFrame {
       ProcsInsertar verDatosCasos = new ProcsInsertar();
       DefaultTableModel modelo = new DefaultTableModel();
       DefaultTableColumnModel modelo2 = new DefaultTableColumnModel(); 
       JTable tabla = new JTable(modelo,modelo2);
       String usuario;
       
    /** Creates new form BuscarCasos */
    public BuscarCasos() {
        JFrame.setDefaultLookAndFeelDecorated(true);
        initComponents();
        l_usuario.setText(usuario);
        rNombre.setVisible(true);
        modelo.addColumn("idCliente");
        modelo.addColumn("NoFolio");
        modelo.addColumn("Cliente");
        modelo.addColumn("Tipo");
        modelo.addColumn("Asunto");
        modelo.addColumn("estudiante");
//        modelo2.getColumn(0).setMaxWidth(5);
//        modelo2.getColumn(1).setMaxWidth(100);
//        modelo2.getColumn(2).setMaxWidth(450);
//        modelo2.getColumn(3).setMaxWidth(100);
//        modelo2.getColumn(4).setMaxWidth(100);
//        modelo2.getColumn(5).setMaxWidth(180);
//        modelo2.getColumn(0).setMaxWidth(0);
//        modelo2.getColumn(0).setMinWidth(0);
//        modelo2.getColumn(0).setPreferredWidth(0);
//        tabla.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
//        tabla.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BC_FolioPanel = new javax.swing.JPanel();
        BC_NoFolio = new javax.swing.JLabel();
        rFolio = new javax.swing.JRadioButton();
        rNombre = new javax.swing.JRadioButton();
        Cbuscar = new javax.swing.JTextField();
        rb_carne = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        l_usuario = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(bufete.BufeteApp.class).getContext().getResourceMap(BuscarCasos.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        BC_FolioPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        BC_FolioPanel.setName("BC_FolioPanel"); // NOI18N

        BC_NoFolio.setFont(resourceMap.getFont("BC_NoFolio.font")); // NOI18N
        BC_NoFolio.setText(resourceMap.getString("BC_NoFolio.text")); // NOI18N
        BC_NoFolio.setName("BC_NoFolio"); // NOI18N

        rFolio.setText(resourceMap.getString("rFolio.text")); // NOI18N
        rFolio.setName("rFolio"); // NOI18N
        rFolio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rFolioActionPerformed(evt);
            }
        });

        rNombre.setText(resourceMap.getString("rNombre.text")); // NOI18N
        rNombre.setName("rNombre"); // NOI18N
        rNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rNombreActionPerformed(evt);
            }
        });

        Cbuscar.setText(resourceMap.getString("Cbuscar.text")); // NOI18N
        Cbuscar.setName("Cbuscar"); // NOI18N
        Cbuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                CbuscarKeyPressed(evt);
            }
        });

        rb_carne.setText(resourceMap.getString("rb_carne.text")); // NOI18N
        rb_carne.setName("rb_carne"); // NOI18N

        javax.swing.GroupLayout BC_FolioPanelLayout = new javax.swing.GroupLayout(BC_FolioPanel);
        BC_FolioPanel.setLayout(BC_FolioPanelLayout);
        BC_FolioPanelLayout.setHorizontalGroup(
            BC_FolioPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(BC_FolioPanelLayout.createSequentialGroup()
                .addGroup(BC_FolioPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, BC_FolioPanelLayout.createSequentialGroup()
                        .addGap(219, 219, 219)
                        .addComponent(rFolio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(rNombre)
                        .addGap(55, 55, 55)
                        .addComponent(rb_carne))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, BC_FolioPanelLayout.createSequentialGroup()
                        .addGap(125, 125, 125)
                        .addComponent(BC_NoFolio, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Cbuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(302, Short.MAX_VALUE))
        );
        BC_FolioPanelLayout.setVerticalGroup(
            BC_FolioPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(BC_FolioPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(BC_FolioPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rFolio)
                    .addComponent(rb_carne)
                    .addComponent(rNombre))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(BC_FolioPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Cbuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BC_NoFolio))
                .addContainerGap(37, Short.MAX_VALUE))
        );

        jLabel1.setIcon(resourceMap.getIcon("jLabel1.icon")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(modelo);
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        l_usuario.setText(resourceMap.getString("l_usuario.text")); // NOI18N
        l_usuario.setName("l_usuario"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(BC_FolioPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 944, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(712, 712, 712)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(l_usuario))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(l_usuario)
                .addGap(9, 9, 9)
                .addComponent(BC_FolioPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 92, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void set_user(String user)
    {
        usuario = user;
    }
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        java.sql.ResultSet res2 =null;
        if (Cbuscar.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null, "Debe ingresar No.Folio");
        //    BC_NoFolioIngreso.setFocusable(true);
        }
         else
        {            
            EditarCasos formEditar = new EditarCasos();
            formEditar.setVisible(true);
            formEditar.set_user(usuario);
         //   EditarCasos editcasos = new EditarCasos();
        try {
            res2 = verDatosCasos.verDatosCaso(jTable1.getValueAt(jTable1.getSelectedRow(),0).toString());
            formEditar.verResultsetObtenerDatosCaso(res2,jTable1.getValueAt(jTable1.getSelectedRow(),0).toString());
        } catch (SQLException ex) {
            Logger.getLogger(BuscarCasos.class.getName()).log(Level.SEVERE, null, ex);
        }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void rFolioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rFolioActionPerformed
        if(rFolio.isSelected()){
            rNombre.setSelected(false);
        }
    }//GEN-LAST:event_rFolioActionPerformed

    private void rNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rNombreActionPerformed
        if(rNombre.isSelected()){
            rFolio.setSelected(false);
        }
    }//GEN-LAST:event_rNombreActionPerformed

    private void CbuscarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_CbuscarKeyPressed
        // TODO add your handling code here:
        
        java.sql.ResultSet res =null;
        if (rFolio.isSelected()){ 
            while(modelo.getRowCount()>0)modelo.removeRow(0);
            try {
                if (Cbuscar.getText().length()==0) Cbuscar.setText("");                 
                if (Cbuscar.getText().length()>0){
                    res = verDatosCasos.verDatosResCaso((Cbuscar.getText()));
                    while (res.next()){
                      //  BC_NoFolioIngreso.addItem(res.getObject("idCaso").toString());
                        Object [] fila = new Object[6]; 
                        for (int i=0;i<6;i++){
                            if (res.getObject(i+1)==null) fila[i]="Sin asignarse";
                            else fila[i] = res.getObject(i+1);
                        }
                        modelo.addRow(fila);
                    }
                }
            } catch (SQLException ex) {
                Logger.getLogger(BuscarCasos.class.getName()).log(Level.SEVERE, null, ex);
            }                
        }
        if (rNombre.isSelected()){
             while(modelo.getRowCount()>0)modelo.removeRow(0);
            try {
                if (Cbuscar.getText().length()==0) Cbuscar.setText("");                 
                if (Cbuscar.getText().length()>0){
                    res = verDatosCasos.verDatosResCaso2((Cbuscar.getText()));
                    while (res.next()){
                  //      BC_NoFolioIngreso.addItem(res.getObject("idCaso").toString());
                        Object [] fila = new Object[6]; 
                        for (int i=0;i<6;i++){
                            if (res.getObject(i+1)==null) fila[i]="Sin asignarse";
                            else fila[i] = res.getObject(i+1);
                        }
                        modelo.addRow(fila);
                    }
                }
            } catch (SQLException ex) {
                Logger.getLogger(BuscarCasos.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        }
        if (rb_carne.isSelected()){
             while(modelo.getRowCount()>0)modelo.removeRow(0);
            try {
                if (Cbuscar.getText().length()==0) Cbuscar.setText("");                 
                if (Cbuscar.getText().length()>0){
                    res = verDatosCasos.verDatosResCaso3((Cbuscar.getText()));
                    while (res.next()){
                  //      BC_NoFolioIngreso.addItem(res.getObject("idCaso").toString());
                        Object [] fila = new Object[6]; 
                        for (int i=0;i<6;i++){
                            if (res.getObject(i+1)==null) fila[i]="Sin asignarse";
                            else fila[i] = res.getObject(i+1);
                        }
                        modelo.addRow(fila);
                    }
                }
            } catch (SQLException ex) {
                Logger.getLogger(BuscarCasos.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        }
    }//GEN-LAST:event_CbuscarKeyPressed

    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
           
            public void run() {
               // JFrame.setDefaultLookAndFeelDecorated(true);
                new BuscarCasos().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel BC_FolioPanel;
    private javax.swing.JLabel BC_NoFolio;
    private javax.swing.JTextField Cbuscar;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel l_usuario;
    private javax.swing.JRadioButton rFolio;
    private javax.swing.JRadioButton rNombre;
    private javax.swing.JRadioButton rb_carne;
    // End of variables declaration//GEN-END:variables
}
